package com.xg.xgaicodemother.utils;

import com.xg.xgaicodemother.aiservers.Assistant;
import dev.langchain4j.data.message.ChatMessage;
import dev.langchain4j.memory.ChatMemory;
import dev.langchain4j.memory.chat.MessageWindowChatMemory;
import dev.langchain4j.model.openai.OpenAiChatModel;
import dev.langchain4j.model.output.FinishReason;
import dev.langchain4j.model.output.TokenUsage;
import dev.langchain4j.rag.content.Content;
import dev.langchain4j.service.AiServices;
import dev.langchain4j.service.Result;
import dev.langchain4j.service.tool.ToolExecution;
import dev.langchain4j.store.memory.chat.ChatMemoryStore;

import java.time.Duration;
import java.util.List;

public class AiTest {


    public static void main(String[] args) {
        OpenAiChatModel model = OpenAiChatModel.builder()
                .apiKey("24d891ffafaf4384b1a60830dcf575ee.g0WXwwTB1hefsZ40")
                .baseUrl("https://open.bigmodel.cn/api/paas/v4")
                //智谱推理模型：GLM-Z1-Flash
                //智谱语言模型：GLM-4-Flash-250414
                .modelName("GLM-Z1-Flash") // 模型名称
                .timeout(Duration.ofSeconds(30))  // 超时时间
                .build();

        Assistant assistant = AiServices.create(Assistant.class, model);
//        String answer = assistant.chat("你好呀，我想要知道2022.7.27的今日热点");
//        System.out.println(answer);

        Result<List<String>> result = assistant.generateOutlineFor("介绍一下雷军");
        List<String> outline = result.content();
        TokenUsage tokenUsage = result.tokenUsage();
        List<Content> sources = result.sources();
        List<ToolExecution> toolExecutions = result.toolExecutions();
        FinishReason finishReason = result.finishReason();
        System.out.println("Outline: " + outline + "\nToken Usage: " + tokenUsage + "\nSources: " + sources + "\nTool Executions: " + toolExecutions + "\nFinish Reason: " + finishReason);
    }

}
